<!DOCTYPE html>
<html lang="en" xmlns:layout="http://www.w3.org/1999/xhtml"
      layout:decorate="~{admin/adminJs}" xmlns:v-on="http://www.w3.org/1999/xhtml">

<body layout:fragment="content">
    <!--搜索栏-->
    <div id="toolbar">
        <div id="search" style="padding:15px">
            <span>表名:</span>
            <el-input v-model="tableName"  style="width: 150px;"></el-input>
            <span>java类名:</span>
            <el-input v-model="javaTableName"  style="width: 150px;"></el-input>
            <span>作者:</span>
            <el-input v-model="author"  style="width: 150px;"></el-input>
            <a id="btn" href="#" v-on:click="query" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
        </div>
        <div id="operator" style="padding:0 0 15px 15px">
            <!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" v-on:click="add('')">新增</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" v-on:click="edit()">修改</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" v-on:click="deleted()">删除</a>-->
        </div>
    </div>
    <!--列表-->
    <table id="table" style="width:100%;" >

    </table>

    <script>

        var filter={ tableName:'',javaTableName:'',author:'' };

        function reload(){
            $('#table').datagrid('reload',filter);
        }

        function closeDialog(isRefresh) {
            if(isRefresh){
                reload();
            }
            $('#editDialog').dialog("close");
        }

        var vm=  new Vue({
            el: '#toolbar',
            data:filter,
            methods: {
                query:function () {
                    reload();
                },
                add:function (id) {
                    EasyuiUtils.openWindows("editDialog",'新增',860,500,'/admin/system/generation/config/edit?id='+id);
                },
                edit:function () {
                    var row=EasyuiUtils.getSelected("#table");
                    if(row){
                        this.add(row.id);
                    }
                },
                deleted:function () {
                    EasyuiUtils.confirmDelete("#table",'/admin/system/generation/config/delete');
                }
            }
        });

        $('#table').datagrid({
            url:'/admin/system/generation/config/listData',
            queryParams:filter,
            columns:[
                [
                    {field:'id',title:'id',align:'center',width:'12%',hidden:true},
                    {field:'tableName',title:'表名',align:'center',width:'12%',hidden:false},
                    {field:'packageName',title:'包名',align:'center',width:'22%',hidden:false},
                    {field:'javaTableName',title:'java类名',align:'center',width:'10%',hidden:false},
                    {field:'controllerDirPre',title:'web访问路径',align:'center',width:'16%',hidden:false},
                    {field:'generatorDir',title:'生成代码路径',align:'center',width:'20%',hidden:false},
                    {field:'author',title:'作者',align:'center',width:'6%',hidden:false},
                    {field:'operator',title:'操作',align:'center',width:'10%',hidden:false,formatter:operator}
                ]
            ],
            striped:true,
            pagination:true,
            rownumbers:true,
            singleSelect:true,
            toolbar:'#toolbar'
        });


        function operator(value,row,index) {
            operatorHtml="";
            operatorHtml+='<a href="#" class="btn btn-primary btn-sm" onclick="editData(\''+row.id+'\',\''+row.tableName+'\')">修改</a>';
            operatorHtml+='<a href="#" class="btn btn-success btn-sm" style="margin-left: 5px;"  onclick="generation(\''+row.id+'\')">生成代码</a>';
            return  operatorHtml;
        }
        function editData(id,tableName) {
            if(id=='null'){
                id='';
            }
            EasyuiUtils.openWindows("editDialog",'新增',860,550,'/admin/system/generation/config/edit?id='+id+"&tableName="+tableName);
        }
        //生成代码
        function generation(id) {
            $.post("/admin/system/generation/config/generation",{id:id},function (data) {
                EasyuiUtils.alert("代码生成成功！");
            })
        }
    </script>
</body>

</html>